﻿using System.Collections;
using UnityEngine;
using UniRx;

public class WalkMonsterAI : AIBase
{
    protected override string getName => "walkMonster";

    private AIStateWander wanderState = new AIStateWander();
    private AIStateTrail trailState = new AIStateTrail();
    private AIStateStandSkill standSkillState = new AIStateStandSkill();

    protected override void InitOutputs()
    {
        outputs.RegisterAxis<float>("horizontalAxis", entity.lifeCycle.GetLifeCycleStream(UnitLifeCycle.LifeType.AIExecute).AsUnitObservable());
        outputs.RegisterAxis<int>("standSkill", entity.lifeCycle.GetLifeCycleStream(UnitLifeCycle.LifeType.AIExecute).AsUnitObservable(), id => id > 0);
    }

    protected override void OnInit()
    {
        base.OnInit();

        RegisterState(wanderState, true);
        RegisterState(trailState);
        RegisterState(standSkillState);

        RegisterTransition(wanderState, trailState, () => (entity as MonsterEntity).hatred != null);
        RegisterTransition(trailState, wanderState, () => (entity as MonsterEntity).hatred == null);

        RegisterTransition(trailState, standSkillState, () => standSkillState.HaveSkillsCanUse());
        RegisterTransition(standSkillState, trailState);
    }
}